package com.lzw.breezeNovel.WebAdmin.controller;


import com.lzw.breezeNovel.WebAdmin.service.BookService;
import com.lzw.breezeNovel.WebAdmin.vo.BookVo;
import com.lzw.breezeNovel.WebAdmin.vo.StatisticsVo;
import com.lzw.breezeNovel.common.result.Result;
import com.lzw.breezeNovel.model.entity.pojo.novel.Book;
import com.lzw.breezeNovel.model.entity.query.PaginationResultQuery;
import com.lzw.breezeNovel.model.entity.query.Search;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;



/**
 * 小说控制类
 */
@RestController
@RequestMapping("/admin/book")
@SuppressWarnings("all")
public class BookController {
    @Resource
    private BookService bookService;

    /**
     * 添加书籍
     */
    @RequestMapping("/addBook")
    public Result addBook(@RequestBody Book book) {
        bookService.addBook(book);
        return Result.ok();
    }

    /**
     * 分页查询书籍
     */
    @PostMapping("/pageBook")
    public Result<PaginationResultQuery<BookVo>> pageBook(@RequestBody Search book) {
        PaginationResultQuery<BookVo> paginationResultVo = bookService.pageBook(book);
       return Result.ok(paginationResultVo);
    }

    /**
     * 删除书籍
     */
    @DeleteMapping("/deleteBook/{id}")
    public Result deleteBook(@PathVariable("id") Integer id) {
        bookService.deleteBook(id);
        return Result.ok();
    }

    /**
     * 批量删除书籍
     */
    @RequestMapping("/deleteBooks/{ids}")
    public Result deleteBooks(@PathVariable("ids") Long[] ids) {
        bookService.deleteBooks(ids);
        return Result.ok();
    }

    /**
     * 修改书籍
     */
    @RequestMapping("/updateBook")
    public Result updateBook(@RequestBody Book book) {
        bookService.updateBook(book);
        return Result.ok();
    }

    /**
     * 统计小说
     */
    @RequestMapping("/getStatistics")
    public Result<StatisticsVo> countBook() {
        StatisticsVo statisticsVo = bookService.countBook();
        return Result.ok(statisticsVo);
    }

}
